want to display a "generating image..." kind of modal dialog, other than the main GUI. This "generating image..." dialog should be temporary, and be displayed and disappear without user intervention.

For displaying this dialog, the Qt code should check for existence of a .txt file in a specific location in the PC's hard disk. If the .txt file exists, then the dialog should pop-up.

For making this dialog disappear, the Qt code should check whether that .txt file contains the string "OK" in the first line. The dialog should disappear only when this "OK" is found, until then it should continue to display "generating image..."

A good way to do this is to use signal slot mechanism. I would like to know, what functions should be used as SIGNALS in both the cases, of displaying and removing the dialog.

So far, I could manage a simple code, illustrating a "generating image..." using signal slot mechanism, but with setValue() and pressing a push button(i.e. involving user intervention), and not with the checking of .txt file or the "OK" string inside that .txt file(user non-intervention).

Please advise me, whether my logic can be implemented? If yes, how? Also, what SIGNALs should be used?

Here is my code:

dialog.h
Qt Code:
  1. #ifndef DIALOG_H
  2. #define DIALOG_H
  3.  
  4. #include <QDialog>
  5. #include <QProgressDialog>
  6.  
  7. #include "mytask.h"
  8.  
  9. namespace Ui {
  10. class Dialog;
  11. }
  12.  
  13. class Dialog : public QDialog
  14. {
  15. Q_OBJECT
  16.  
  17. public:
  18. explicit Dialog(QWidget *parent = 0);
  19. ~Dialog();
  20.  
  21. private slots:
  22. void on_modalButton_clicked();
  23.  
  24. private:
  25. Ui::Dialog *ui;
  26. MyTask *myTask;
  27. };
  28.  
  29. #endif // DIALOG_H
To copy to clipboard, switch view to plain text mode 

mytask.h
Qt Code:
  1. #ifndef MYTASK_H
  2. #define MYTASK_H
  3.  
  4. #include <QObject>
  5. #include <QProgressDialog>
  6. #include <QTimer>
  7. #include <QDebug>
  8.  
  9. #define NUM_TASKS 50000
  10.  
  11. class MyTask : public QObject
  12. {
  13. Q_OBJECT
  14. public:
  15. explicit MyTask(QObject *parent = 0);
  16.  
  17. signals:
  18.  
  19. public slots:
  20. void perform();
  21. void cancel();
  22.  
  23. private:
  24. int steps;
  25. QTimer *t;
  26. };
  27.  
  28. #endif // MYTASK_H
To copy to clipboard, switch view to plain text mode 

dialog.cpp
Qt Code:
  1. #include "dialog.h"
  2. #include "ui_dialog.h"
  3.  
  4. Dialog::Dialog(QWidget *parent) :
  5. QDialog(parent),
  6. ui(new Ui::Dialog)
  7. {
  8. ui->setupUi(this);
  9. }
  10.  
  11. Dialog::~Dialog()
  12. {
  13. delete ui;
  14. }
  15.  
  16. void Dialog::on_modalButton_clicked()
  17. {
  18. myTask = new MyTask;
  19. }
To copy to clipboard, switch view to plain text mode 

mytask.cpp
Qt Code:
  1. #include "mytask.h"
  2.  
  3. MyTask::MyTask(QObject *parent) :
  4. QObject(parent), steps(0)
  5. {
  6. pd = new QProgressDialog("generating image...", 0, 0, NUM_TASKS);
  7. connect(pd, SIGNAL(canceled()), this, SLOT(cancel()));
  8.  
  9. t = new QTimer(this);
  10. connect(t, SIGNAL(timeout()), this, SLOT(perform()));
  11. t->start(0);
  12.  
  13. /* to make a window modal in nature. */
  14. pd->setModal(true);
  15.  
  16. }
  17.  
  18. void MyTask::perform()
  19. {
  20. disconnect(pd, SIGNAL(canceled()), this, SLOT(cancel()));
  21. pd->setValue(steps); //... perform one percent of the operation
  22. steps++;
  23. qDebug()<<steps;
  24. if (steps > pd->maximum())
  25. {
  26. t->stop();
  27. }
  28. }
  29.  
  30. void MyTask::cancel()
  31. {
  32. t->stop(); //... cleanup
  33. }
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include "dialog.h"
  2. #include <QApplication>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. Dialog w;
  8. w.show();
  9.  
  10. return a.exec();
  11. }
To copy to clipboard, switch view to plain text mode